package com.joysuch.wwyt.risk.controller;

import com.joysuch.wwyt.core.common.ajax.ResultBean;
import com.joysuch.wwyt.risk.bean.RiskStableEvalutionBean;
import com.joysuch.wwyt.risk.entity.RiskStableEvalution;
import com.joysuch.wwyt.risk.service.RiskStableEvalutionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/risk/stableEvalution")
@Api(tags = "/risk/stableEvalution 固有风险评估")
public class RiskStableEvalutionController {

    @Autowired
    private RiskStableEvalutionService riskStableEvalutionService;

    /**
     * 增加
     *
     * @param entity
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "增加")
    public Object add(@Valid @RequestBody RiskStableEvalution entity) {
        try {
            RiskStableEvalution evalution = riskStableEvalutionService.add(entity);
            return ResultBean.success(entity);
        } catch (Exception e) {
            log.error("创建失败", e);
            return ResultBean.fail(101, "创建失败");
        }
    }

    /**
     * 更新
     *
     * @param entity
     * @return
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public Object update(@Valid @RequestBody RiskStableEvalution entity) {
        try {
            RiskStableEvalution rse = riskStableEvalutionService.update(entity);
            return ResultBean.success(rse);
        } catch (Exception e) {
            log.error("更新失败", e);
            return ResultBean.fail(101, "更新失败");
        }
    }

    /**
     * 查看
     *
     * @param entity
     * @return
     */
    @PostMapping("/findOne")
    @ApiOperation(value = "查看")
    public Object findOne(@Valid @RequestBody RiskStableEvalution entity) {
        try {
            RiskStableEvalutionBean bean = riskStableEvalutionService.findOne(entity);
            return ResultBean.success(bean);
        } catch (Exception e) {
            log.error("查询失败", e);
            return ResultBean.fail(101, "查询失败");
        }
    }

    /**
     * 删除
     *
     * @param entity
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public Object delete(@Valid @RequestBody RiskStableEvalution entity) {
        try {
            riskStableEvalutionService.delete(entity);
            return ResultBean.success("");
        } catch (Exception e) {
            log.error("删除失败", e);
            return ResultBean.fail(101, "删除失败");
        }
    }
}
